package com.example.mapper.one_to_one;

import com.example.bean.Card;
import com.example.bean.Person;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * @program: mybatis_maven
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-10 19:52
 **/
public interface CardMapper {
    @Select({"select c.id cid, c.number number, c.pid pid\n" +
            "from card c\n" +
            "where c.id = #{id};"})
    @Results(id = "card", value = {
            @Result(
                    property = "id",
                    column = "cid"
            ), @Result(
            property = "number",
            column = "number"
    ), @Result(
            property = "pid",
            column = "pid"
    ), @Result(
            property = "person",
            column = "pid",
            javaType = Person.class,
            /*
                    // 被包含对象的变量名
                  // 被包含对象的实际数据类型
                         // 根据查询出的card表中的pid字段来查询person表
                      one、@One 一对一固定写法
                      select属性：指定调用哪个接口中的哪个方法
                   */
            one = @One(select = "com.example.mapper.PersonMapper.selectById"))
    })
    Card selectById(Integer id);

}
